
<div class="content">
	<div class="content_i">
    <?php
		
		 // Thong tin dang nhap
		echo "<h2>";
			echo CHtml::image(Yii::app()->baseUrl."/assets/icon/icon-16-info.png");
			echo " Thông tin Menu Item";
		echo "</h2>";
			
        echo CHtml::beginForm(
			array($this->controller_id."/save",
				"menuitem_id"=>$row["id"],
				"menu_id"=>$menu_id,
				"language_id"=>$language_id
			),
			"post",
			array("id" => "form_edit")
		);
		
		echo "<table cellpadding='3' cellspacing='0 border='0' width='100%'>";
		
			echo "<tr>";
				echo "<td class='label' width='100'>"."Menu"."</td>";
				echo "<td>";
					$list_menu = array();
					$list_menu[0] = "-- Chọn Menu --";
					$menus = menu::model()->findAll(array(
						"condition" => "enable = 1",
						"order"=>"`order` ASC"
					));
					
					if (!is_null($menus))
					{
						foreach($menus as $menu)
						{
							$list_menu[$menu["id"]] = $menu["name"];
						}
					}
					if ($row->id == 0)
					{
						echo CHtml::dropDownList("menu_id",$menu_id, $list_menu,
							array("id"=>"menu_id"));
					}
					else
					{
						echo CHtml::dropDownList("menu_id",$row->menu_id, $list_menu, 
							array("id"=>"menu_id"));
					}
				echo "</td>";
			echo "</tr>";
			
			echo "<tr>";
				echo "<td class='label' width='100'>"."MenuItem cha"."</td>";
				echo "<td>";
					$list_parent = array();
					$list_parent[0] = "-- Parent --";
					
					$menuitem_parent = NULL;
					
					if ($row->id == 0)
					{
						$menuitem_parent = menuitem::model()->findAll(array(
							"condition" => "menu_id = " . $menu_id . " AND parent_id = 0"
						));		
					}
					else
					{
						$menuitem_parent = menuitem::model()->findAll(array(
							"condition" => "menu_id = " . $row->menu_id . " AND parent_id = 0"
						));
					}
					
					if (! is_null($menuitem_parent))
					{
						foreach($menuitem_parent as $p)	
						{
							$list_parent[$p["id"]] = $p["name"];
						}
					}
					echo CHtml::dropDownList("parent_id",$row->parent_id, $list_parent, 
						array("id"=>"parent_id"));
				echo "</td>";
			echo "</tr>";
			
			echo "<tr>";
				echo "<td class='label' width='120'>"."Ngôn ngữ"."</td>";
				echo "<td>";
					$list_language = array(0=>"-- Chọn ngôn ngữ --");
					
					$languages = language::model()->findAll();
					foreach($languages as $language)
					{
						$list_language[$language["id"]] = $language["name"];	
					}
					
					echo CHtml::dropDownList("language_id",$row->language_id, $list_language);
				echo "</td>";
			echo "</tr>";
			
			echo "<tr>";
				echo "<td class='label' width='100'>"."Tên MenuItem"."</td>";
				echo "<td>";
				echo CHtml::textField("name", $row->name, 
					array('style'=>'width:400px;'));
				echo "</td>";
			echo "</tr>";
			
			echo "<tr>";
				echo "<td class='label' width='100'>"."Alias"."</td>";
				echo "<td>";
				echo CHtml::textField("alias", $row->alias, 
					array('style'=>'width:400px;'));
				echo "</td>";
			echo "</tr>";
			
			echo "<tr>";
				echo "<td class='label' width='100'>"."Params"."</td>";
				echo "<td>";
				echo CHtml::textField("params", $row->params, 
					array('style'=>'width:400px;'));
				echo "</td>";
			echo "</tr>";
			
			
			
			echo "<tr>";
				echo "<td class='label' width='120' valign='top'>"."Meta Description"."</td>";
				echo "<td >";
				echo CHtml::textArea("meta_description",$row->meta_description,
					 array('style'=>'width:400px;height:50px;'));
				echo "</td>";
			echo "</tr>";
			
			echo "<tr>";
				echo "<td class='label' width='120' valign='top'>"."Meta Keywords"."</td>";
				echo "<td >";
				echo CHtml::textArea("meta_keywords",$row->meta_keywords,
					 array('style'=>'width:400px;height:50px;'));
				echo "</td>";
			echo "</tr>";
			
			echo "<tr>";
				echo "<td>"."</td>";
				echo "<td>";
					 // Submit Button
						echo "<div class='space_5'></div>";
	
						echo 
							"<div class='button' id='button_submit'>" .
								"<div style='float:left; width:20px;'>" .
									CHtml::image(Yii::app()->baseUrl."/assets/icon/icon-16-save.png") .
								"</div>" .
								"<div style='float:left; min-width:40px;font-weight:bold'>".
									"Save" .
								"</div>" .
							"</div>";
						
						echo 
							"<div class='button' id='button_savenew'>" .
								"<div style='float:left; width:20px;'>" .
									CHtml::image(Yii::app()->baseUrl."/assets/icon/icon-16-plus.png") .
								"</div>" .
								"<div style='float:left; min-width:40px;font-weight:bold'>".
									" Save & New" .
								"</div>" .
							"</div>";
						
						echo 
							"<div class='button' id='button_apply'>" .
								"<div style='float:left; width:20px;'>" .
									CHtml::image(Yii::app()->baseUrl."/assets/icon/icon-16-tick.png") .
								"</div>" .
								"<div style='float:left; min-width:40px;font-weight:bold'>".
									" Apply" .
								"</div>" .
							"</div>";
							
						echo 
							"<div class='button' id='button_cancel'>" .
								"<div style='float:left; width:20px;'>" .
									CHtml::image(Yii::app()->baseUrl."/assets/icon/icon-16-check.png") .
								"</div>" .
								"<div style='float:left; min-width:50px;font-weight:bold'>".
									"Close" .
								"</div>" .
							"</div>";
							
				echo "</td>";
			echo "</tr>";
		echo "</table>";
		echo CHtml::endForm();
	?>
    </div>
</div><!-- end div right -->

<script language="javascript">
$(document).ready(function(){

	$('#button_submit').click(function(){
		$('#form_edit').submit();
	});
	
	$('#button_savenew').click(function(){
		$('#form_edit').attr("action","<?php
			echo Yii::app()->createUrl(
				$this->module_id."/" . $this->controller_id."/savenew",
				array(
					"menuitem_id"=>$row["id"],
					"menu_id"=>$menu_id,
					"language_id"=>$language_id
				)
			);
		?>");
		$('#form_edit').submit();
	});
	
	$('#button_apply').click(function(){
		$('#form_edit').attr("action","<?php
			echo Yii::app()->createUrl(
				$this->module_id."/" . $this->controller_id."/apply",
				array(
					"menuitem_id"=>$row["id"],
					"menu_id"=>$menu_id,
					"language_id"=>$language_id
				)
			);
		?>");
		$('#form_edit').submit();
	});
	
	$('#button_cancel').click(function(){
		window.location = '<?php
			$url = Yii::app()->createUrl(
				$this->route . "/view",
				array(
					"menu_id"=>$menu_id,
					"language_id" => $language_id
				)
			);
			echo $url;
		?>';
	});
	
	
	$('#menu_id').change(function(){
		//alert(this.value);
		url = '<?php
			$url = Yii::app()->createUrl(
				$this->route."/list_parent_id"
			);
			echo $url;
		?>' + '&menu_id=' + this.value;
		//alert(url);
		
		$.post(
			url,
			function(data){
				$('#parent_id').html(data);
			}
		);
		
	});
});
</script>
